import { BasicColumn, FormSchema } from '@/components/Table';
import { h, ref } from 'vue';
import { Tag } from 'ant-design-vue';
import { ywUserSelectList } from '@/api/heng/ywManage';
import { ApiSelect } from '@/components/Form';
import util from '@/utils/util';

import { useMessage } from '@/hooks/web/useMessage';
import Ainput from '@/views/bookManage/components/account/Ainput.vue';
import { VxeFormItemProps, VxeGridPropTypes } from '@/components/VxeTable';
import { changeEnd } from 'codemirror';
import { style } from '@logicflow/extension/es/bpmn-elements/presets/icons';
import { categoryList } from '@/api/heng/ex';

type CheckedType = boolean | string | number;
// BasicColumn[]

// VxeColumnPropTypes.CellRender

/**
 */
export const vxeTableColumns: VxeGridPropTypes.Columns = [
  {
    title: '试卷名称',
    field: 'name',
    showOverflow: 'title',
  },

  {
    title: '考试模式',
    field: 'model',
    showOverflow: 'title',
    align: 'center',
    formatter: ({ cellValue, row, column }) => {
      let val = '';
      if (!cellValue) {
        return val;
      }
      switch (cellValue) {
        case 1:
          val = '单一模块';
          break;
        case 2:
          val = '整张试卷';
          break;
      }
      return val;
    },
    width: 140,
  },
  {
    title: '试卷类型',
    field: 'ruleType',
    showOverflow: 'title',
    align: 'center',
    formatter: ({ cellValue, row, column }) => {
      let val = '';

      switch (cellValue) {
        case 0:
          val = '普通计分(支持面试)';
          break;
        case 1:
          val = '团队试卷';
          break;
      }
      return val;
    },
    width: 140,
  },
  // {
  //   title: '考试分钟数',
  //   field: 'limitTime',
  //   align: 'center',
  //   width: 140,
  // },
  {
    title: '是否打乱顺序',
    field: 'isDerange',
    showOverflow: 'title',
    align: 'center',
    formatter: ({ cellValue, row, column }) => {
      let val = '';
      if (!cellValue) {
        return val;
      }
      switch (cellValue) {
        case 0:
          val = '否';
          break;
        case 1:
          val = '是';
          break;
      }
      return val;
    },
    width: 90,
  },
  {
    title: '是否强制交卷',
    field: 'isCoerce',
    showOverflow: 'title',
    align: 'center',
    formatter: ({ cellValue, row, column }) => {
      let val = '';
      if (!cellValue) {
        return val;
      }
      switch (cellValue) {
        case 0:
          val = '否';
          break;
        case 1:
          val = '是';
          break;
      }
      return val;
    },
    width: 90,
  },
  {
    title: '是否禁用',
    field: 'status',
    showOverflow: 'title',
    align: 'center',
    formatter: ({ cellValue, row, column }) => {
      let val = '';

      switch (cellValue) {
        case 0:
          val = '否';
          break;
        case 1:
          val = '是';
          break;
      }
      return val;
    },
    width: 90,
  },
  {
    title: '创建时间',
    field: 'createTime',
    width: 180,
    align: 'center',
  },
  {
    width: 150,
    title: '操作',
    align: 'center',
    field: '',
    slots: { default: 'action' },
    fixed: 'right',
  },
];

export const vxeTableFormSchema: VxeFormItemProps[] = [
  {
    span: 5,
    field: 'keyword',
    title: '查询',
    itemRender: {
      props: {
        placeholder: '查询',
      },
      name: 'AInput',
    },
  },
  {
    span: 5,
    field: 'status',
    title: '是否禁用',
    itemRender: {
      defaultValue: 0,
      props: {
        placeholder: '请选择',
        style: { width: '100%' },
        options: [
          { label: '否', value: 0 },
          { label: '是', value: 1 },
        ],
      },
      name: 'ASelect',
    },
  },
  {
    span: 5,
    itemRender: {
      name: 'VxeButtonGroup',
      options: [
        { type: 'reset', content: '重置' },
        { type: 'submit', content: '查询', status: 'primary' },
      ],
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '试卷名称',
    field: 'name',
    component: 'Input',
    required: true,
  },
  {
    field: 'model',
    label: '考试模式',
    component: 'Select',
    defaultValue:1,
    componentProps: {
      options: [
        { label: '单一模块', value: 1 },
        // { label: '整张试卷', value: 2 },
      ],
    },
    required: true,
  },
  {
    field: 'limitTime',
    label: '考试分钟数',
    component: 'InputNumber',
    required: false,
    ifShow({ values }) {
      return values.ruleType === 1;
    },
  },
  {
    field: 'isDerange',
    label: '是否打乱顺序',
    component: 'Select',
    componentProps: {
      options: [
        { label: '是', value: 1 },
        { label: '否', value: 0 },
      ],
    },
  },
  {
    field: 'isCoerce',
    label: '是否强制交卷',
    component: 'Select',
    componentProps: {
      options: [
        { label: '是', value: 1 },
        { label: '否', value: 0 },
      ],
    },
  },
  {
    field: 'ruleType',
    label: '计分规则',
    component: 'Select',
    defaultValue:1,
    required:true,
    helpMessage:"请在'团队管理'中设置答对或答错分数",
    componentProps: {
      options: [
        { label: '区分团队(核心功能)', value: 1 },
        { label: '普通计分(面试)', value: 0 },
      ],
    },
  },
  {
    field: 'groups',
    label: '题目分类',
    required: false,
    slot: 'title_group',
    colProps: { lg: 24, md: 24 },
  },
  //
];

export const titleGroupColumns: VxeGridPropTypes.Columns = [
  {
    title: '分类',
    field: 'categoryName',
    showOverflow: 'title',
    align: 'center',
  },
  {
    title: '选题类型',
    field: 'type',
    showOverflow: 'title',
    align: 'center',
    width: 140,
    formatter: ({ cellValue, row, column }) => {
      let val = '';
      // if (!cellValue) {
      //   return val;
      // }
      switch (cellValue) {
        case 0:
          val = '全部';
          break;
        case 1:
          val = '部分';
          break;
      }
      return val;
    },
  },
  {
    title: '是否测试',
    field: 'azTest',
    showOverflow: 'title',
    align: 'center',
    width: 140,
    formatter: ({ cellValue, row, column }) => {
      let val = '';
      // if (cellValue!=null) {
      //   return val;
      // }
      switch (cellValue) {
        case 0:
          val = '否';
          break;
        case 1:
          val = '是';
          break;
      }
      return val;
    },
  },
  {
    title: '是否打乱选项',
    field: 'isDerangeOption',
    showOverflow: 'title',
    align: 'center',
    width: 100,
    formatter: ({ cellValue, row, column }) => {
      let val = '';
      // if (cellValue!=null) {
      //   return val;
      // }
      switch (cellValue) {
        case 0:
          val = '否';
          break;
        case 1:
          val = '是';
          break;
      }
      return val;
    },
  },
  {
    title: '考试分钟数',
    field: 'limitTime',
    showOverflow: 'title',
    align: 'center',
    width: 150
  },
  {
    title: '题目数量',
    field: 'type',
    showOverflow: 'title',
    align: 'center',
    formatter: ({ cellValue, row, column }) => {
      let val = '';
      if (row.type == 1) {
        val = `部分选题:${row.num}道`;
      } else if (row.type == 0){
        val = '点击编辑查看';
      }
      return val;
    },
    width: 140,
  },
  {
    width: 150,
    title: '操作',
    align: 'center',
    field: '',
    slots: { default: 'action' },
    fixed: 'right',
  },
];

export const chooseQuestionColumns: VxeGridPropTypes.Columns = [
  // {
  //   type: 'checkbox',
  //   title: '',
  //   field: 'seq',
  //   width: 40,
  // },
  {
    title: '题目内容',
    field: 'title',
    showOverflow: 'title',
  },
  {
    title: '图片',
    field: 'img',
    showOverflow: 'title',
    align: 'center',
    width: 80,
    slots: {
      default:"img_slot"
    }
  },
  {
    title: '类型',
    field: 'type',
    showOverflow: 'title',
    align: 'center',
    width: 140,
  },
  {
    title: '分类',
    field: 'categoryName',
    showOverflow: 'title',
    align: 'center',
    width: 140,
  },
  {
    title: '考试分钟数',
    field: 'limitTime',
    showOverflow: 'title',
    align: 'center',
    width: 120,
  },
  {
    title: '上级分类',
    field: 'pcategoryName',
    showOverflow: 'title',
    align: 'center',
    width: 140,
  },
  {
    title: '解析',
    field: 'explain',
    align: 'center',
  },
  // {
  //   title: '创建时间',
  //   field: 'createTime',
  //   width: 180,
  //   align: 'center',
  // },
  {
    width: 120,
    title: '操作',
    align: 'center',
    field: '',
    slots: { default: 'action' },
    fixed: 'right',
  },
];

export const titleGroupform: FormSchema[] = [
  {
    field: 'categoryId',
    label: '分类',
    required: true,
    slot: 'categoryId',
    // component: 'ApiTreeSelect',
    // componentProps: {
    //   resultField: 'data',
    //   labelField: 'categoryName',
    //   valueField: 'categoryId',
    //   childrenField: 'children',
    //   params: { status: 1 },
    //   api: categoryList,
    // },
  },
  {
    field: 'categoryName',
    label: '分类(模块)名称',
    component:"Input",
    required: true,

  },
  {
    field: 'ruleType',
    label: 'ruleType',
  },

  {
    field: 'limitTime',
    label: '考试分钟数',
    component: 'InputNumber',
    required: false,
    // ifShow({ values }) {
    //   return values.ruleType === 0;//ruleType 0 为面试
    // },
  },
  {
    field: 'type',
    label: '选题类型',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: '部分', value: 1 },
        { label: '全部', value: 0 },
      ],
    },
  },
  {
    field: 'isDerangeOption',
    label: '是否打乱选项',
    component: 'Select',
    required: false,
    componentProps: {
      options: [
        { label: '否', value: 0 },
        { label: '是', value: 1 },
      ],
    },
  },
  {
    field: 'startTime',
    label: '开考时间',
    component: 'TimePicker',
    required: false,
    componentProps: {
      valueFormat:'HH:mm:ss',
      format:"HH:mm:ss"
    },
  },
  {
    field: 'azTest',
    label: '是否测试',
    component: 'Select',
    componentProps: {
      options: [
        { label: '是', value: 1 },
        { label: '否', value: 0 },
      ],
    },
  },
  {
    field: 'partQuestions',
    label: '已选题目',
    required: false,
    slot: 'question_select',
    colProps: { lg: 24, md: 24 },
    ifShow: ({ values }) => values.type === 1,
  },
  {
    field: 'all_questions',
    label: '全部题目',
    required: false,
    slot: 'all_questions',
    // colProps: { lg: 24, md: 24 },
    ifShow: ({ values }) => values.type === 0,
  },

  {
    field: 'trueType0',
    label: '正确得分(普通计分模式)',
    component: 'InputNumber',
    required: false,
    ifShow({ values }) {
      return values.ruleType === 0;//ruleType 0 为面试
    },
  },
];
